package top.dbpanda.cmsjpa.learn.juc;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class TestFutureTask {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        MyCallableThread myCallableThread = new MyCallableThread();
        FutureTask<Integer> futureTask = new FutureTask<>(myCallableThread);
        new Thread(futureTask).start();
        Integer integer = futureTask.get();
        System.out.println(integer);

    }

}

class MyCallableThread implements Callable<Integer> {
    @Override
    public Integer call() {
        int sum = 0;
        for (int i = 0; i <= 100; i++) {
            sum += i;
        }
        return sum;
    }
}
